home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / melt / melt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-26  |  2.9 KB  |  112 lines

  1. /************************************************************************
  2.  Source code of an attempt to create the melting screen ala DOOM.
  3.  It looks like a melting screen except it shrinks the screen towards
  4.  the bottom.
  5.  I am cheating and using FASTGRAPH to set the video mode and allocate
  6.  extra pages. It would be easy to call an interrupt to set the mode and
  7.  malloc to allocate the pages.
  8.  
  9.  Send any comments to;
  10.  John Gonzalez
  11.  71414,1353
  12. *************************************************************************/
  13. #include <conio.h>
  14. #include <dos.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17.  
  18. #include "fastgraf.h"
  19.  
  20.  
  21. #define SCREENWIDTH    320
  22. #define SCREENHEIGHT    200
  23.  
  24. void Scale(unsigned int column,unsigned int destheight,unsigned int ypos,
  25.        unsigned char *frompage,unsigned char *topage);
  26.  
  27. int height[SCREENWIDTH / 4];
  28. unsigned int screen_offset[SCREENHEIGHT];
  29.  
  30. main()
  31. { unsigned int i, j, k, a;
  32.   char *vpage, *hpage1, *hpage2;
  33.   randomize();
  34.  
  35.   /* Initialize height array with 1 to avoid division by 0 */
  36.   for(i= 0;i < SCREENWIDTH / 4;i++)
  37.     height[i]= 1;
  38.  
  39.   /* Initialize screen offset table */
  40.   for(i= 0;i < SCREENHEIGHT;i++)
  41.     screen_offset[i]= i * SCREENWIDTH;
  42.  
  43.   /* Set mode 19 */
  44.   fg_setmode(19);
  45.  
  46.   /* Allocate a page, read in a pcx and create a far pointer to it */
  47.   fg_allocate(1);
  48.   fg_setpage(1);
  49.   if(fg_showpcx("first.pcx",0))
  50.     { fg_freepage(1);
  51.       exit(1);
  52.     };
  53.   hpage1= MK_FP(fg_getaddr(),0);
  54.  
  55.   /* Again */
  56.   fg_allocate(2);
  57.   fg_setpage(2);
  58.   if(fg_showpcx("second.pcx",0))
  59.     { fg_freepage(1);
  60.       fg_freepage(2);
  61.       exit(2);
  62.     };
  63.   hpage2= MK_FP(fg_getaddr(),0);
  64.  
  65.   /* Make a pointer to the visual page */
  66.   fg_setpage(0);
  67.   vpage= MK_FP(fg_getaddr(),0);
  68.  
  69.   while(!kbhit())
  70.     { for(j= 0;j < SCREENWIDTH / 4;j++)
  71.     {
  72.       /* This section updates the top of the screen */
  73.       a= j * 4;
  74.       k= height[j];
  75.       while(k--)
  76.         { vpage[a]= hpage2[a++];
  77.           vpage[a]= hpage2[a++];
  78.           vpage[a]= hpage2[a++];
  79.           vpage[a]= hpage2[a];
  80.           a+= SCREENWIDTH - 3;
  81.         };
  82.  
  83.       /* Now do the scaling */
  84.       Scale(j * 4,199 - height[j],height[j],hpage1,vpage);
  85.     };
  86.       for(j= 0;j < SCREENWIDTH / 4;j++)
  87.     if(height[j] < 199) height[j]+= rand() % 8 + 4;
  88.     };
  89.  
  90.   /* free pages */
  91.   fg_freepage(1);
  92.   fg_freepage(2);
  93.   fg_setmode(3);
  94. };
  95.  
  96. void Scale(unsigned int column,unsigned int destheight,unsigned int ypos,
  97.        unsigned char *frompage,unsigned char *topage)
  98. { unsigned int yratio, y= 0, offset;
  99.   if(ypos > SCREENHEIGHT - 1 || destheight == 0) return;
  100.   yratio= (SCREENHEIGHT << 8) / destheight; /* 8.8 */
  101.   topage+= screen_offset[ypos] + column;
  102.   while(destheight--)
  103.     { offset= screen_offset[y >> 8] + column;
  104.       *topage++= *(frompage + offset++);
  105.       *topage++= *(frompage + offset++);
  106.       *topage++= *(frompage + offset++);
  107.       *topage= *(frompage + offset);
  108.       topage+= SCREENWIDTH - 3;
  109.       y+= yratio;
  110.     };
  111. };
  112.